package server;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import netPacks.message;

/**
 *
 * @author user
 */
public class mainServerEntry {
    
    /**
     *
     */
    public static void main(String args[]){
        mainServer SERVER = mainServer.getInstance();
        InetAddress tempAdd = null;
        int tempPort = 0;
        if(args[0]!=null){
    		String[] temp = args[0].split(":");
        	try {
    			tempAdd = InetAddress.getByName(temp[0]);
    		} 
    		catch (UnknownHostException e1) {
    			System.err.println("Cannot get backup IP address.\n");
    			e1.printStackTrace();
    		}
            SERVER.setBackupAddress(tempAdd);
        	if(temp.length > 1){
        		tempPort = Integer.parseInt(temp[1]);
        		mainServer.getInstance().setBackupPort(tempPort);
        	}
        	else{
        		System.out.println("No backup port given, using Default port 6000.");
        	}
    		System.out.println("Backup server port and IP address set.");
        }
        else{
        	System.out.println("No backup info given. Continuing with no Backup.");
        }
        SERVER.start();
    	System.out.println("Server initialized.");
		msgHandler MSGHANDLER = msgHandler.getInstance();
    	MSGHANDLER.start();
    	System.out.println("Message Handler initialized.");
    	matcher MATCHER = matcher.getInstance();
    	MATCHER.start();
    	System.out.println("Matcher initialized.");
        
    }
}
